package com.ljf.framework.context;

import com.ljf.framework.LjfManager;
import com.ljf.framework.context.model.*;
import com.ljf.framework.exception.LjfException;

/**
 * 上下文处理器 [默认实现类]
 *
 */
public class LjfContextDefaultImpl implements LjfContext {

	/**
	 * 默认的上下文处理器对象
	 */
	public static LjfContextDefaultImpl defaultContext = new LjfContextDefaultImpl();

	/**
	 * 默认的错误提示语
	 */
	public static final String ERROR_MESSAGE = "未能获取有效的上下文处理器";

	/**
	 * 获取当前请求的 [Request] 对象
	 */
	@Override
	public LjfRequest getRequest() {
		throw new LjfException(ERROR_MESSAGE);
	}

	/**
	 * 获取当前请求的 [Response] 对象
	 */
	@Override
	public LjfResponse getResponse() {
		throw new LjfException(ERROR_MESSAGE);
	}

	/**
	 * 获取当前请求的 [存储器] 对象
	 */
	@Override
	public LjfStorage getStorage() {
		throw new LjfException(ERROR_MESSAGE);
	}

	/**
	 * 校验指定路由匹配符是否可以匹配成功指定路径
	 */
	@Override
	public boolean matchPath(String pattern, String path) {
		throw new LjfException(ERROR_MESSAGE);
	}

	@Override
	public void syncContext(Object object) {
		LjfContextForThreadLocalStorage.Box box = (LjfContextForThreadLocalStorage.Box) object;
		LjfContextForThreadLocalStorage.setBox(box.getRequest(),box.getResponse(),box.getStorage());
	}

	@Override
	public Object getSyncObject() {
		LjfContextForThreadLocalStorage.setBox(new LjfRequestDefault(),new LjfResponseDefault(),new LjfStorageDefault());
		return LjfContextForThreadLocalStorage.getBox();
//		throw new LjfException(ERROR_MESSAGE);
	}

}
